package com.example.common.entity;

import jakarta.persistence.*;
import lombok.Data;

import java.math.BigInteger;
import java.time.LocalDateTime;

@Entity
@Table(name = "sys_dict")
@Data
public class SysDict {
    @Id
    @Column(name = "dict_id", nullable = false)
    private BigInteger dictId;
    
    @Column( nullable = false, unique = true)
    private String name;
    
    private String description;
    
    // create_by
    @ManyToOne
    @JoinColumn(name = "create_by", referencedColumnName = "username")
    private SysUser creator;
    
    // update_by
    @ManyToOne
    @JoinColumn(name = "update_by", referencedColumnName = "username")
    private SysUser updator;
    
    @Column(name = "create_time")
    private LocalDateTime createTime;
    
    @Column(name = "update_time")
    private LocalDateTime updateTime;
    
    public BigInteger getDictId() {
        return dictId;
    }
    
    public void setDictId(BigInteger dictId) {
        this.dictId = dictId;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Transient
    public String getCreateBy() {
        return creator.getUsername();
    }
    
    public void setCreateBy(String createBy) {
        SysUser user = new SysUser();
        user.setUsername(createBy);
        this.creator = user;
    }
    
    @Transient
    public String getUpdateBy() {
        return updator.getUsername();
    }
    
    public void setUpdateBy(String updateBy) {
        SysUser user = new SysUser();
        user.setUsername(updateBy);
        this.updator = user;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }
}
